<?php

namespace app\admin\controller\paotui;

use app\common\controller\Backend;

/**
 * 溢价价格管理
 *
 * @icon fa fa-circle-o
 */
class Extraprice extends Backend
{
    
    /**
     * ExtraPrice模型对象
     * @var \app\admin\model\paotui\ExtraPrice
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();

        $this->model = new \app\admin\model\paotui\ExtraPrice();

    }

    public function index()
    {
        if($this->request->isPost()){
            $params = $this->request->post("row/a");
            $type = 1;
            $value = $params['general'];
            $this->model->where(['type'=>$type])->delete();
            if($value){
                foreach ($value as $v){
                    $model = new \app\admin\model\paotui\ExtraPrice();
                    $model->save(['type'=>$type,
                        'money'=>$v['money'],
                        'note'=>$v['note'],]);
                }
            }
            $this->success("请求成功");
            exit;
        }

        //普送
        $model = new \app\admin\model\paotui\ExtraPrice();
        $generalList = $model->where(['type'=>"1"])->select();
        $general = [];
        foreach ($generalList as $v){
            $general[] = ['money'=>$v['money'],'note'=>$v['note']];
        }
        $this->assign('general',json_encode($general));

        return $this->fetch();
    }
}
